import { application_info } from '@/services/sickbeds';
import calculate_age from '@/utils/age';
import { ActionType, ProDescriptions } from '@ant-design/pro-components';
import { Divider, Modal, Spin } from 'antd'
import React, { useEffect, useState } from 'react'

interface Iprops {
    isShowDetailModal: (show: boolean) => void;
    isDetailModalOpen: boolean;
    id: number | undefined;
    status: number | undefined;
    actionRef1: React.MutableRefObject<ActionType | undefined>;
}
const Detail = (props: Iprops) => {
    const { isDetailModalOpen, isShowDetailModal, id, actionRef1, status } = props

    // 存储申请详情
    const [applicationInfo, setApplicationInfo] = useState<any>(undefined)

    // 页面初始化
    useEffect(() => {
        // 获取申请详情
        const getData = async () => {
            if (id) {
                let res: any = await application_info({ id })
                console.log('申请详情', res);
                if (res.code == 200) {
                    setApplicationInfo(res.data)
                }
            }
        }
        getData()
    }, [])
    return (
        <Modal
            title="详情"
            centered
            open={isDetailModalOpen}
            onCancel={() => isShowDetailModal(false)}
            destroyOnClose={true}
            width={1000}
            footer={null}
        >
            <Divider />
            {applicationInfo == undefined ?
                <div
                    style={{
                        margin: '20px 0',
                        marginBottom: '20px',
                        padding: '30px 50px',
                        textAlign: 'center',
                    }}
                >
                    <Spin size="large" />
                </div> : <>
                    <ProDescriptions
                        dataSource={applicationInfo}
                        title='申请信息'
                        column={3}
                        columns={[
                            {
                                title: '姓名',
                                key: 'name',
                                dataIndex: 'name',
                            },
                            {
                                title: "性别",
                                key: 'sex',
                                dataIndex: 'sex',
                                valueEnum: {
                                    0: {
                                        text: '未知'
                                    },
                                    1: {
                                        text: '男'
                                    },
                                    2: {
                                        text: '女'
                                    }
                                }
                            },
                            {
                                title: '年龄',
                                dataIndex: 'age',
                                key: 'age',
                                hideInSearch: true,
                            },
                            {
                                title: '联系方式',
                                dataIndex: 'phone',
                                key: 'phone',
                            },
                            {
                                title: '申请人',
                                key: 'type',
                                dataIndex: 'type',
                                valueEnum: {
                                    1: {
                                        text: '自己'
                                    },
                                    2: {
                                        text: '家属'
                                    }
                                }
                            },
                            {
                                title: '是否有住院史',
                                key: 'was_hospitalization',
                                dataIndex: 'was_hospitalization',
                                valueEnum: {
                                    0: {
                                        text: '否'
                                    },
                                    1: {
                                        text: '是'
                                    },
                                }
                            },
                            {
                                title: '病史',
                                key: 'medical_history',
                                dataIndex: 'medical_history',
                            },
                            {
                                title: '申请时间',
                                key: 'create_time',
                                dataIndex: 'create_time',
                            },

                        ]}
                    ></ProDescriptions>
                    <ProDescriptions
                        title="审批详情"
                        column={3}
                        dataSource={applicationInfo}
                        columns={
                            [
                                {
                                    title: '审批人',
                                    key: 'manage_name',
                                    dataIndex: 'manage_name',
                                },
                                {
                                    title: "审批状态",
                                    key: 'status',
                                    dataIndex: 'status',
                                    valueEnum: {
                                        0: {
                                            text: "待审批",
                                        },
                                        1: {
                                            text: '已同意'
                                        },
                                        2: {
                                            text: '已拒绝'
                                        }
                                    }
                                },
                                {
                                    title: '审批时间',
                                    key: 'processed_time',
                                    dataIndex: 'processed_time',
                                },
                                {
                                    title: `${status === 1 ? '同意原因' : '拒绝原因'}`,
                                    key: 'reason',
                                    dataIndex: 'reason',
                                },
                            ]
                        }
                    ></ProDescriptions>
                </>}

        </Modal>
    )
}
export default Detail